#include <a_master>
#include <ServerQuery>
#include <string>

new ip[] = "83.222.114.142";
new port[3] = {8903, 8902, 8901};

public OnFilterScriptInit()
{
	//print(" --- ServerQuery TestFS loaded ---");
 	return 1;
}

public OnFilterScriptExit()
{
	//print(" --- ServerQuery TestFS unloaded ---");
 	return 1;
}

TestServerQuery()
{
	new SQplayers=0;
    if(GetInfoPacket(ip,port[0]))
    {
		new string[256], hostname[128], gamemode[128], mapname[128];
		iGetHostname(hostname);
		iGetGamemode(gamemode);
		iGetMapname(mapname);
		SQplayers = iGetPlayers();
		format(string,sizeof(string),"Server Info (%s:%d)\n\nHostname: %s\nPassworded: %d\nPlayers: %d/%d\nGamemode: %s\nMapname: %s",ip,port,hostname,iIsPassworded(),SQplayers,iGetMaxPlayers(),gamemode,mapname);
		printf("\n%s\n", string);
	}
	else print("retrieving ServerInformation failed");

	if(GetRulesPacket(ip,port[0]))
	{
	    printf("Serverrules (%s:%d)\n",ip,port);
	    new rulename[MAX_RULENAMESIZE], rulevalue[MAX_RULEVALUESIZE];
	    new SQrules=rGetRulesAmount();
	    for(new i=0;i<SQrules;i++)
	    {
	        rGetRuleName(i,rulename);
	        rGetRuleValue(i,rulevalue);
	        printf("%s: %s",rulename,rulevalue);
	    }
	}
	else print("retrieving ServerRules failed");

 	if(SQplayers >= 100) printf("too many players for retrieving Playerpacket (max 99)");
	else
	{
		if(GetPlayerPacket(ip,port[0]))
		{
		    new players=cGetPlayers();
		    if(players<=0) print("\nno players");
		    new playername[MAX_PLAYER_NAME];
		    for(new i;i<players;i++)
		    {
		    	cGetPlayerName(i,playername);
		    	printf("ID %d: %s, Score: %d",i,playername,cGetPlayerScore(i));
		    }
		}
		else print("retrieving PlayerPacket failed");
	}

}

public OnRconCommand(cmd[])
{
	if(strcmp("test all",cmd)==0) TestServerQuery();
	return 1;
}






